package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldAssetsRecord;
import com.cleaningcloud.cld.domain.dto.CldAssetsRecordDto;
import com.cleaningcloud.cld.domain.dto.CldAssetsRecordProjectDto;
import com.cleaningcloud.cld.domain.vo.CldAssetsRecordVo;
import com.cleaningcloud.cld.service.ICldAssetsRecordService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资产记录Controller
 *
 * @author cleaningcloud
 * @date 2024-10-06
 */
@RestController
@RequestMapping("/record")
public class CldAssetsRecordController extends BaseController {
    @Autowired
    private ICldAssetsRecordService cldAssetsRecordService;

    /**
     * 查询资产记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CldAssetsRecordDto cldAssetsRecord) {
        startPage();
        List<CldAssetsRecordVo> list = cldAssetsRecordService.selectCldAssetsRecordList(cldAssetsRecord);
        return getDataTable(list);
    }

    /**
     * 查询资产维修记录
     */
    @GetMapping("/getRepairList")
    public TableDataInfo getRepairList(CldAssetsRecord cldAssetsRecord) {
        startPage();
        List<CldAssetsRecordVo> list = cldAssetsRecordService.getRepairList(cldAssetsRecord);
        return getDataTable(list);
    }


    /**
     * 查询投放记录
     */
    @GetMapping("/deliveryList")
    public AjaxResult deliveryList(CldAssetsRecordDto cldAssetsRecord) {
        List<CldAssetsRecordVo> list = cldAssetsRecordService.selectCldAssetsRecordList(cldAssetsRecord);
        return success(list);
    }

    /**
     * 获取资产记录详细信息
     */
    @GetMapping(value = "/{assetsRecordId}")
    public AjaxResult getInfo(@PathVariable("assetsRecordId") Long assetsRecordId) {
        return success(cldAssetsRecordService.selectCldAssetsRecordByAssetsRecordId(assetsRecordId));
    }

    /**
     * 新增资产记录
     */
    @Log(title = "资产记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldAssetsRecordDto cldAssetsRecord) {
        return toAjax(cldAssetsRecordService.insertCldAssetsRecord(cldAssetsRecord));
    }

    /**
     * 新增资产记录 -> 批量提交 项目设置资产
     */
    @Log(title = "资产记录", businessType = BusinessType.INSERT)
    @PostMapping("/batchAdd")
    public AjaxResult batchAdd(@RequestBody CldAssetsRecordProjectDto cldAssetsRecordDto) {

        return toAjax(cldAssetsRecordService.batchInsertCldAssetsRecord(cldAssetsRecordDto));
    }

    /**
     * 修改资产记录
     */
    @Log(title = "资产记录", businessType = BusinessType.INSERT)
    @PutMapping
    public AjaxResult edit(@RequestBody CldAssetsRecord cldAssetsRecord) {

        return toAjax(cldAssetsRecordService.updateCldAssetsRecord(cldAssetsRecord));
    }


    /**
     * 修改资产记录
     */
    @Log(title = "资产记录", businessType = BusinessType.INSERT)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody CldAssetsRecord cldAssetsRecord) {
        return toAjax(cldAssetsRecordService.auditCldAssetsRecord(cldAssetsRecord));
    }

    /**
     * 删除资产记录
     */
    @RequiresPermissions("cld:assets:remove")
    @Log(title = "删除资产记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{assetsRecordId}")
    public AjaxResult remove(@PathVariable Long[] assetsRecordId)
    {
        return toAjax(cldAssetsRecordService.deleteCldAssetsRecordByAssetsRecordIds(assetsRecordId));
    }
}
